<?php
class Remove_model extends Model {

    function Remove_model()
    {
        parent::Model();
        $this->load->database();
    }

    /**
     * remove item
     *
     * removes an item from the database as well as all vote records
     * that are associated
     *
     * @param int $id
     */
    function remove_item($id)
    {
        //remove item
        $this->db->delete('item', array('IID' => $id));
        //remove vote w/ vote.iid
        $this->db->delete('vote', array('IID' => $id));
    }

    /**
     * remove user
     *
     * removes a user from the database. also removes all items associated
     * with the user and any votes associated with those items
     *
     * @param int $id
     */
    function remove_user($id)
    {
        //get item.id for vote delete
        $Q = "SELECT item.IID FROM item WHERE UID='$id';";
        $R = $this->db->query($Q);
        $IID = $R->result();
        //remove user
        $this->db->delete('user', array('UID' => $id));
        //remove item w/ userid
        $this->db->delete('item', array('UID' => $id));
        //remove vote w/ itemid
        foreach($IID as $item)
            {
                $this->db->delete('vote', array('IID' => $item->IID));
            }
    }

}
//EOF
